package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.BaseCategoryTrademark;
import com.atguigu.gmall.model.product.BaseTrademark;
import com.atguigu.gmall.model.product.CategoryTrademarkVo;
import com.atguigu.gmall.product.service.BaseCategoryTrademarkService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags ="SPU分类品牌")
@RestController
@RequestMapping("admin/product/baseCategoryTrademark")
@RefreshScope //自动刷新配置
public class BaseCategoryTrademarkController {

    @Autowired
    private BaseCategoryTrademarkService baseCategoryTrademarkService;

    @ApiOperation("根据category3Id获取品牌列表")
    @GetMapping("findTrademarkList/{category3Id}")
    public Result findTrademarkList(@PathVariable Long category3Id){
       List<BaseTrademark> baseTrademarkList= baseCategoryTrademarkService.findTrademarkList(category3Id);
       return Result.ok(baseTrademarkList);
    }

    @ApiOperation("根据category3Id获取可选品牌列表")
    @GetMapping("findCurrentTrademarkList/{category3Id}")
    public Result findCurrentTrademarkList(@PathVariable Long category3Id){
        List<BaseTrademark> baseTrademarkList= baseCategoryTrademarkService.findCurrentTrademarkList(category3Id);
        return Result.ok(baseTrademarkList);

    }

    @ApiOperation("删除分类品牌")
    @DeleteMapping("remove/{category3Id}/{trademarkId}")
    public Result removeById(@PathVariable Long category3Id,@PathVariable Long trademarkId){
        baseCategoryTrademarkService.removeById(category3Id,trademarkId);
        return Result.ok();
    }

    @ApiOperation("新增分类品牌")
    @PostMapping("save")
    public Result save(@RequestBody CategoryTrademarkVo categoryTrademarkVo){
        baseCategoryTrademarkService.save(categoryTrademarkVo);
        return Result.ok();
    }
}